package org.je.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;

/**
 * @author fanyifeng
 */
public class MemUtil
{

	public static void clean(ByteBuffer bf) {
		if (bf == null || bf.isDirect() == false) {
			return;
		}
		try {
			Field f = bf.getClass().getDeclaredField("cleaner");
			f.setAccessible(true);
			Object cleaner = f.get(bf);
			Method md = cleaner.getClass().getDeclaredMethod("clean");
			md.invoke(cleaner);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
}
